package com.uton.rfidcontroller.viewmodel.activity_model;

import android.databinding.ObservableField;

import com.uton.rfidcontroller.common.interfaces.INetController;
import com.uton.rfidcontroller.common.net.RetrofitFactory;
import com.uton.rfidcontroller.model.CarDealerDetailModel;
import com.uton.rfidcontroller.viewmodel.base.BaseViewModel;

import java.util.HashMap;

/**
 * Created by 王家宝 on 2017/10/19.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public abstract class CarDealerDetailActivityViewModel extends BaseViewModel {

    private String carDealerId;
    /**
     * 车行名称
     */
    public final ObservableField<String> carDealerName = new ObservableField<>("");
    /**
     * 车行手机号
     */
    public final ObservableField<String> carDealerMobile = new ObservableField<>("");
    /**
     * 商户详细地址
     */
    public final ObservableField<String> carDealerAddress = new ObservableField<>("");
    /**
     * 商户介绍
     */
    public final ObservableField<String> carDealerDescr = new ObservableField<>("");


    public CarDealerDetailActivityViewModel(String carDealerId) {
        this.carDealerId = carDealerId;
        refreshData();
    }

    @Override
    public void refreshData() {
        //查询车行信息
        queryCarDealerDetail();
    }


    private void queryCarDealerDetail() {
        HashMap<String, Object> tempData = new HashMap<>();
        tempData.put("carDealerId", carDealerId);
        go(RetrofitFactory.getInstance().carDealerDetail(tempData), new INetController<CarDealerDetailModel>() {
            @Override
            public void onSuccess(CarDealerDetailModel response) {
                carDealerName.set(response.getCarDealerName());
                carDealerMobile.set(response.getCarDealerMobile());
                carDealerAddress.set(response.getCarDealerAddress());
                carDealerDescr.set(response.getCarDealerDescr());
            }

            @Override
            public void onError() {

            }

            @Override
            public void onComplete() {

            }
        });
    }

}
